<?php

include_once 'Statement.php';
include_once 'Expression.php';
include_once 'CompoundAssignmentOperator.php';

/**
 * Represents an assign statement 
 * 
 * @package UC_PHPCodeModel
 * @author Uros Calakovic
 * @example ../Examples/AssignmentStatementExample.php
 */

class AssignStatement extends Statement
{

    /**
     * The AssignStatement constructor
     * @param Expression $Left The expression to assign to
     * @param Expression $Right The expression to assign to $Left
     * @param string $CompoundOperator One of the CompoundAssignmentOperator constants or null
     */
    
    public function __construct(
        Expression $Left, Expression $Right, $CompoundOperator = null)
    {
        parent::__construct();
        $this->set_Left($Left);
        $this->set_Right($Right);
        $this->set_CompoundOperator($CompoundOperator);
    }
    
    /**
     * Used for making private / protected variables 
     * accessible from outside the class.
     * 
     * @param string $name Name of the field to be accessed
     * @param mixed $value The value the field should be set to, usually a collection.
     * @see CodeObject::__set()
     */
    
    public function __set($name, $value)
    {
        parent::__set($name, $value);
        
        if($name == 'Left')
        {
            $this->set_Left($value);
        }
        
        if($name == 'Right')
        {
            $this->set_Right($value);
        }
        
        if($name == 'CompoundOperator')
        {
            $this->set_CompoundOperator($value);
        }
    }
    
    /**
     * Used for making private / protected variables 
     * accessible from outside the class.
     * 
     * @param string $name Name of the field to be accessed
     * @return mixed The field that $name specified, usually a collection
     * @see CodeObject::__get()
     */
    
    public function __get($name)
    {
        $ret = parent::__get($name);
        
        if($ret != null)
        {
            return $ret;
        }
        
        if($name == 'Left')
        {
            return $this->get_Left();
        }
        
        if($name == 'Right')
        {
            return $this->get_Right();
        }
        
        if($name == 'CompoundOperator')
        {
            return $this->get_CompoundOperator();
        }
    }
    
    /**
     * The $Left getter method
     * @return Expression 
     */
    
    public function get_Left()
    {
        return $this->Left;
    }
    
    /**
     * The $Left setter method
     * @param Expression $Left The left side of the  
     * 
     * @assert (123) throws PHPUnit_Framework_Error
     * @assert ('name') throws PHPUnit_Framework_Error
     * @assert (new stdClass()) throws PHPUnit_Framework_Error
     */

    public function set_Left(Expression $Left)
    {
        $this->Left = $Left;
    }

    /**
     * The $Right getter method
     * @return Expression 
     */
    
    public function get_Right()
    {
        return $this->Right;
    }
    
    /**
     * The $Right setter method
     * @param Expression $Right 
     * 
     * @assert (123) throws PHPUnit_Framework_Error
     * @assert ('name') throws PHPUnit_Framework_Error
     * @assert (new stdClass()) throws PHPUnit_Framework_Error
     */
  
    public function set_Right(Expression $Right)
    {
        $this->Right = $Right;
    }

    /**
     * The $CompoundOperator getter method
     * @return CompoundAssignmentOperator 
     */
    
    public function get_CompoundOperator()
    {
        return $this->CompoundOperator;
    }

    /**
     * The $CompoundOperator setter method
     * 
     * $CompoundOperator can be set to one of the CompoundAssignmentOperator
     * constants or to null. If null is used (which is default)
     * the simple assignment operator (=) will be used
     * to generate the statement.
     * 
     * @param CompoundAssignmentOperator $CompoundOperator
     * @throws InvalidArgumentException 
     * 
     * @assert (123) throws InvalidArgumentException
     * @assert ('name') throws InvalidArgumentException
     * @assert (new stdClass()) throws InvalidArgumentException
     */
    
    public function set_CompoundOperator($CompoundOperator)
    {
        if(CompoundAssignmentOperator::Defines($CompoundOperator) 
            || $CompoundOperator == null)
        {
            $this->CompoundOperator = $CompoundOperator;
        }
        else
        {
            throw new InvalidArgumentException(
                'The value must be ' .
                'one of the CompoundAssignmentOperator constants');
        }
    }

    /**
     * The expression to assign to
     * @var Expression 
     */
    
    private $Left;
    
    /**
     * The expression to assign to $Left
     * @var Expression 
     */
    
    private $Right;
    
    /**
     * The compound assignment operator to use or null
     * 
     * If $CompoundOpeartor is null, the simple assignment operator (=)
     * will be used to generate the statement.
     * 
     * @var CompoundAssignmentOperator 
     */
    
    private $CompoundOperator = null;
}

?>
